package com.wu.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wu.bean.UpdateBean;
import com.wu.util.BaseUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UpdateController
 * @Author xwu36
 * @Date 2019/3/4 11:24
 * @Version 1.0
 * @Description
 **/
@RestController
public class UpdateController {

    @Value("${app-version}")
    String newVersion;

    @Value("${app-note}")
    String note;

    @Value("${app-url}")
    String url;
    ObjectMapper mapper=new ObjectMapper();

    @GetMapping("/update")
    public String getUpdateInfo(@RequestParam String appid,String version) throws JsonProcessingException {
        System.out.println(appid+"/"+version);
        UpdateBean updateBean=new UpdateBean();
        if (version!=newVersion) {
            updateBean.setUpdateState(1);
            updateBean.setNewVersion(newVersion);
            updateBean.setUpdateMsg(BaseUtil.getUtil().ISOtoUtd8(note));
            updateBean.setUrl(url);
        }else {
            updateBean.setUpdateState(0);
        }
        return mapper.writeValueAsString(updateBean);
    }
}
